/*
 * filter.cxx
 *
 *  Created on: Jun 9, 2011
 *      Author: Erich Malzer
 */

#include "crypto/filter.h"
#include <sstream>
#include <cmath>
#include "logger.h"



CFilter::CFilter() {
	printl(0, __FILE__, "constructing CFilter");

}

CFilter::~CFilter() {

}

void CFilter::changeFilters(unsigned int pMin, unsigned int pMax, unsigned int pSampleRate, unsigned int pFftFrameSize) {
	printl(0, __FILE__, "changing Filters");

	mMin=floor(((double)pMin/((double)pSampleRate/(double)pFftFrameSize)));
	if(mMin<1)
		mMin=1;

	mMax=ceil(((double)pMax/((double)pSampleRate/(double)pFftFrameSize)));
	if(mMax>(double)pFftFrameSize/2)
		mMax=((double)pFftFrameSize/2);
}


//BUG: If mMax is the absolute maximum of pFftFrameSize/2, also one frequency is cut because of the
// condition i=mMax;i<pFftFrameSize/2+1;
void CFilter::cutFrequencies(fftw_complex *pFftData, unsigned int pFftFrameSize){
	unsigned int i;

	for(i=0;i<mMin;i++){
		pFftData[i][0]=0;
		pFftData[i][1]=0;
	}
	for(i=mMax;i<pFftFrameSize/2+1;i++){
		pFftData[i][0]=0;
		pFftData[i][1]=0;
	}

	//Scale the remaining frequencies
	/*for(i=1;i<pFftFrameSize/2+1;i++){
		pFftData[i][0]*=1.66;
	}*/
}

unsigned int CFilter::getMin(){
	return mMin;
}

unsigned int CFilter::getMax(){
	return mMax;
}
